package com.jsbj.user.controller;


import com.alibaba.fastjson.JSONObject;
import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.user.entities.SysOrg;
import com.jsbj.user.entities.SysTenant;
import com.jsbj.user.service.ISysOrgService;
import com.jsbj.user.service.ISysTenantService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 组织结构表（集团-公司-项目-标段） 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-org")
@Api(value = "组织管理", tags = "组织管理")
//@ApiIgnore
public class SysOrgController extends BaseController {

    @Autowired
    private ISysOrgService sysOrgService;

    @Autowired
    private ISysTenantService sysTenantService;

    @ApiIgnore
    @ApiOperation("通过用户id+项目编码查询标段列表")
    @PostMapping("/getInfoByUserIdAndTenantCode")
    public ResultBean<List<SysOrg>> getInfoByUserIdAndTenantCode(@RequestParam String userId, @RequestParam String tenantCode) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getInfoByUserIdAndTenantCode(userId, tenantCode));
    }

//    @ApiIgnore
    @ApiOperation("通过用户id+项目编码查询标段列表  首页定制化接口  试验检测系统显示检测单位 其他系统显示标段")
    @PostMapping("/getInfoByUserIdAndTenantCodeHomePage")
    public ResultBean<List<SysOrg>> getInfoByUserIdAndTenantCodeHomePage(@RequestParam String userId, @RequestParam String tenantCode, @RequestBody String data) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getInfoByUserIdAndTenantCodeHomePage(userId, tenantCode,data));
    }

    @ApiOperation("通过用户id+项目编码查询标段列表  用户中心设备管理定制化接口  增加试验检测单位")
    @PostMapping("/getInfoByUserIdAndTenantCodeEqu")
    public ResultBean<List<SysOrg>> getInfoByUserIdAndTenantCodeEqu(@RequestParam String userId, @RequestParam String tenantCode) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getInfoByUserIdAndTenantCodeEqu(userId, tenantCode));
    }

    @ApiIgnore
    @ApiOperation("通过用户id+项目编码+标段类型(选填)查询检测单位列表")
    @PostMapping("/getTestUnitByUserIdAndTenantCode")
    public ResultBean<List<SysOrg>> getTestUnitByUserIdAndTenantCode(@RequestParam String userId, @RequestParam String tenantCode,
                                                                     @RequestParam(required = false) String secType) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getTestUnitByUserIdAndTenantCode(userId, tenantCode,secType));
    }

    @ApiIgnore
    @ApiOperation("通过用户id+项目编码+标段code查询检测单位列表")
    @PostMapping("/getTestUnitByUserIdAndTenantCodeAndOrgCode")
    public ResultBean<List<SysOrg>> getTestUnitByUserIdAndTenantCodeAndOrgCode(@RequestParam String userId, @RequestParam String tenantCode,
                                                                               @RequestParam String orgCode) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getTestUnitByUserIdAndTenantCodeAndOrgCode(userId, tenantCode,orgCode));
    }

    @ApiIgnore
    @ApiOperation("通过组织编码查询标段详情")
    @PostMapping("/getInfoByOrgCode")
    public ResultBean<SysOrg> getInfoByOrgCode(@RequestParam String orgCode, @RequestParam String tenantCode) {
        return new ResultBean<SysOrg>(sysOrgService.getInfoByOrgCode(orgCode, tenantCode));
    }

    @ApiIgnore
    @ApiOperation("通过用户id+项目编码查询施工标段+公司组织树")
    @PostMapping("/getSGInfoByTenatCode")
    public ResultBean<List<SysOrg>> getSGInfoByTenatCode(@RequestParam String userId, @RequestParam String tenantCode) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getSGInfoByTenatCode(userId, tenantCode));
    }

    @ApiIgnore
    @ApiOperation("通过项目编码查询标段列表")
    @PostMapping("/api/getInfoByTenantCode")
    public ResultBean<List<SysOrg>> getInfoByTenantCode(@RequestParam String tenantCode) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getInfoByTenantCode(tenantCode));
    }

    @ApiOperation("查询列表")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysOrg.class)})
    @PostMapping("/getListData")
    public ResultBean<PageReq> getListData(@RequestBody String inParam) {
        return new ResultBean<PageReq>(getPage(sysOrgService.getListData(inParam)));
    }

    @PostMapping("/getListDataQxAll")
    public ResultBean<List<SysOrg>> getListDataQxAll(@RequestBody String inParam) {
        return new ResultBean<List<SysOrg>>(sysOrgService.getListDataQxAll(inParam));
    }

    @ApiOperation("查询所有租户下拉框")
    @PostMapping("/getAllTenant")
    public ResultBean<List<SysTenant>> getAllTenant() {
        return new ResultBean<List<SysTenant>>(sysTenantService.getAllTenant());
    }

    @ApiOperation("新增或编辑保存")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true)}
    )
    @PostMapping("saveOrUpdateData")
    public ResultBean<JSONObject> saveOrUpdateData(@RequestBody SysOrg sysOrg){
        return sysOrgService.saveOrUpdateData(sysOrg);
    }

    @ApiOperation("查看详情")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "id（行）", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysOrg.class)})
    @PostMapping("getDetail")
    public ResultBean<SysOrg> getDetail(@RequestParam String id){
        return new ResultBean<SysOrg>(sysOrgService.getDetail(id));
    }

    @ApiOperation("删除数据")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "id（行）", required = true)}
    )
    @PostMapping("deleteData")
    public ResultBean<JSONObject> deleteData(@RequestParam String id){
        return sysOrgService.deleteData(id);
    }

    @ApiIgnore
    @ApiOperation("通过用户id+项目编码查询公司组织树")
    @PostMapping("/getAllInfoByTenatCode")
    public List<SysOrg> getAllInfoByTenatCode(@RequestParam String userId, @RequestParam String tenantCode) {
        return sysOrgService.getAllInfoByTenatCode(userId, tenantCode);
    }
}

